package Practice;

import java.util.Scanner;

public class Comparable {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] grade = new int[n][3];
        int num = 0;

        for (int i=0;i<n;i++){
            for (int j=0;j<3;j++){
                grade[i][j] = sc.nextInt();
            }
        }

        for (int i=0;i<n-1;i++){
            for (int k=i+1;k<n;k++) {
                boolean isComparable = true; // 用于标识是否“旗鼓相当”
                for (int j = 0; j < 3; j++) {
                    int diff = Math.abs(grade[i][j] - grade[k][j]);
                    if (diff > 5) {
                        isComparable = false; // 如果任何一科的差距超过5，则标记为不相当
                        break;
                    }
                }
                if (isComparable) {
                    int totalScoreI = grade[i][0] + grade[i][1] + grade[i][2];
                    int totalScoreJ = grade[k][0] + grade[k][1] + grade[k][2];
                    int totalDiff = Math.abs(totalScoreI - totalScoreJ);

                    if (totalDiff <= 10) {
                        num++;
                    }
                }
            }
        }
        System.out.println(num);
    }
}
